Continious tracks
The transmitter will often go dark for 10 to 12 hours, due to weather, right in the middle of an otherwise good track. The model requires regular intervals to estimate the turning angles and temporal autocorrelation. As a track hits one of these walls, call it the end of a track, and begin a new track once the weather improves. We can remove any micro-tracks that are less than three days. Specify a duration, calculate the number of tracks and the number of removed points. Iteratively.
How did the filter change the extent of tracks?




sink(“Bayesian/Multi_RW.jags”) cat(" model{
#Constants
pi <- 3.141592653589
##argos observation error##
argos_prec[1:2,1:2] <- inverse(argos_sigma*argos_cov[,])
#Constructing the covariance matrix
argos_cov[1,1] <- 1
argos_cov[1,2] <- sqrt(argos_alpha) * rho
argos_cov[2,1] <- sqrt(argos_alpha) * rho
argos_cov[2,2] <- argos_alpha
for(i in 1:ind){
for(g in 1:tracks[i]){
## Priors for first true location
#for lat long
y[i,g,1,1:2] ~ dmnorm(argos[i,g,1,1,1:2],argos_prec)
#First movement - random walk.
y[i,g,2,1:2] ~ dmnorm(y[i,g,1,1:2],iSigma)
###First Behavioral State###
state[i,g,1] ~ dcat(lambda[]) ## assign state for first obs
#Process Model for movement
for(t in 2:(steps[i,g]-1)){
#Behavioral State at time T
logit(phi[i,g,t,1]) <- alpha_mu[state[i,g,t-1]]
phi[i,g,t,2] <- 1-phi[i,g,t,1]
state[i,g,t] ~ dcat(phi[i,g,t,])
#Turning covariate
#Transition Matrix for turning angles
T[i,g,t,1,1] <- cos(theta[state[i,g,t]])
T[i,g,t,1,2] <- (-sin(theta[state[i,g,t]]))
T[i,g,t,2,1] <- sin(theta[state[i,g,t]])
T[i,g,t,2,2] <- cos(theta[state[i,g,t]])
#Correlation in movement change
d[i,g,t,1:2] <- y[i,g,t,] + gamma[state[i,g,t]] * T[i,g,t,,] %*% (y[i,g,t,1:2] - y[i,g,t-1,1:2])
#Gaussian Displacement
y[i,g,t+1,1:2] ~ dmnorm(d[i,g,t,1:2],iSigma)
}
#Final behavior state
logit(phi[i,g,steps[i,g],1]) <- alpha_mu[state[i,g,steps[i,g]-1]]
phi[i,g,steps[i,g],2] <- 1-phi[i,g,steps[i,g],1]
state[i,g,steps[i,g]] ~ dcat(phi[i,g,steps[i,g],])
## Measurement equation - irregular observations
# loops over regular time intervals (t)
for(t in 2:steps[i,g]){
# loops over observed locations within interval t
for(u in 1:idx[i,g,t]){
zhat[i,g,t,u,1:2] <- (1-j[i,g,t,u]) * y[i,g,t-1,1:2] + j[i,g,t,u] * y[i,g,t,1:2]
#for each lat and long
#argos error
argos[i,g,t,u,1:2] ~ dmnorm(zhat[i,g,t,u,1:2],argos_prec)
}
}
}
}
###Priors###
#Process Variance
iSigma ~ dwish(R,2)
Sigma <- inverse(iSigma)
##Mean Angle
tmp[1] ~ dbeta(20, 20)
tmp[2] ~ dbeta(10, 10)
# prior for theta in 'traveling state'
theta[1] <- (2 * tmp[1] - 1) * pi
# prior for theta in 'foraging state'
theta[2] <- (tmp[2] * pi * 2)
##Move persistance
# prior for gamma (autocorrelation parameter)
#from jonsen 2016
gamma[2] ~ dbeta(1.5, 2) ## gamma for state 2
dev ~ dbeta(1,1) ## a random deviate to ensure that gamma[1] > gamma[2]
gamma[1] <- gamma[2] + dev
##Behavioral States
#Hierarchical structure across motnhs
#Intercepts
alpha_mu[1] ~ dnorm(0,0.386)
alpha_mu[2] ~ dnorm(0,0.386)
#Variance
alpha_tau[1] ~ dt(0,1,1)I(0,)
alpha_tau[2] ~ dt(0,1,1)I(0,)
#Probability of behavior switching
lambda[1] ~ dbeta(1,1)
lambda[2] <- 1 - lambda[1]
##Argos priors##
#longitudinal argos error
argos_sigma ~ dunif(0,10)
#latitidunal argos error
argos_alpha~dunif(0,10)
#correlation in argos error
rho ~ dunif(-1, 1)
}"
,fill=TRUE)
sink()
## user system elapsed
## 0.461 0.006 552.923